# Table B.1: Association Between Salience and Ex-Post Closeness of the Referendum


# 1. Load Packages ----
library(stargazer)
library(lfe)
library(tidyverse)

# 2. Read in Data ----

load(file = "df_voxit_swissvotes.RData")

# 3. Data Preparation ----
# Aggregate the data at the federal level
df_federal <- voxit_sv %>%
  group_by(anr, datum_merge) %>%
  summarise(salience = mean(salience),
            distance = mean(closeness),
            turnout_admin = mean(turnout_admin))

# 4. Regressions ----
lm.out1 <- felm(formula = salience ~ distance | 0 | 0| datum_merge, 
                data = df_federal)
summary(lm.out1)

lm.out3 <- felm(formula = salience ~ distance | datum_merge | 0| datum_merge , 
                data = df_federal)
summary(lm.out3)

# 5. Regression Table ----
stargazer::stargazer(lm.out1, lm.out3,
                     type = "latex",
                     star.cutoffs = c(0.1, 0.05, 0.01),
                     star.char = c("*", "**", "***"),
                     summary=T,
                     keep = c("^distance"),
                     covariate.labels = c("Distance"),
                     df = F,
                     dep.var.caption="Dependent variable: Salience",
                     dep.var.labels.include=F,
                     float = F, 
                     omit.table.layout ="n",
                     keep.stat = c("n"),
                     add.lines = list(c("Voting day FE", "No", "Yes")),
                     out = "TableB1.tex")
